<template>
	<view class="count">
		<view class="bg">
			<image src="/static/chaoji.png" class="shou" mode=""></image>
		</view>
		<!-- 		<view class="qing">
			请求授权
		</view> -->
		<view class="">
			<image src="/static/logo.png" class="imgLogo" mode=""></image>
		</view>
		<view class="tit">
			你好，欢迎登录
		</view>
		<button class="btn" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber" :plain="true">
			手机号一键登录
		</button>
		<!-- 	<button class="btn" @click="logged" :plain="true">
			微信账号一键登录
		</button> -->
		<button @click="zanbuLogin" class="btns" :plain="true">
			暂不登录
		</button>
		<view class="bottom">
			<view class="imgGou">
				<image src="/static/show2.png" class="img" @click="check=false" v-if="check" mode=""></image>
				<image src="/static/show1.png" class="img" @click="check=true" v-else mode=""></image>
			</view>
			<view class="text">
				阅读并同意 <text @click="user">《用户协议》</text> 和<text @click="privacy">《隐私协议》</text>
			</view>
		</view>
		<u-popup width="90%" border-radius="30" mode="center" v-model="showYS">
			<view class="wai">
				<view class="biao_top">
					<u-parse :html="contentName"></u-parse>
				</view>
				<view class="tow">
					<u-parse :html="content"></u-parse>
				</view>
			</view>
		</u-popup>

		<u-popup mode="center" width="90%" border-radius="25" v-model="show">
			<view class="detil p-20">
				<view class="tit">
					{{title}}
				</view>
				<u-parse :html="count"></u-parse>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '用户协议',
				count: '',
				show: false,
				show2: false,
				check: false,
				showYS: false,
				content: '',
				contentName: "",
				obj: {},
				mobile: ''
			}
		},
		onShow() {
			this.initList()
		},
		methods: {
			// 暂不登录
			zanbuLogin() {
				uni.switchTab({
					url: '/pages/home/index'
				})
			},
			async initList() {
				let n = await this.$api.agreement()
				this.obj = n.content
			},
			changeRaid(e) {
				console.log(e);
			},
			// 用户协议
			async user() {
				this.count = uni.getStorageSync('user_agree')
				this.title = '用户协议'
				this.show = true
			},
			// 隐私协议
			async privacy() {
				this.count = uni.getStorageSync('privacy_agree')
				this.title = '隐私政策'
				this.show = true
			},
			// 判断有没有登陆过
			logged() {
				uni.login({
					provider: 'weixin', //使用微信登录
					success: async (res) => {
						let m = await this.$api.login({
							code: 'test'
						})
						uni.setStorageSync('token', m.data.token)
						let n = await this.$api.userInfo()
						uni.setStorageSync('userInfo', n.data)
						uni.setStorageSync('upload_token', n.data.upload.token)
						uni.setStorageSync('domain', n.data.upload.domain)
						uni.setStorageSync('upload_domain', n.data.upload.endpoint)
						if (m.code == 200) {
							uni.switchTab({
								url: '/pages/home/index'
							})
						}
					}
				})
			},
			decryptPhoneNumber(e) {
				console.log(e, '55555555555555555555');
				if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
					return this.$msg('您已拒绝授权')
				}
				if (!this.check) {
					return this.$msg('请勾选协议')
				}
				if (!this.check) {
					return this.$msg('请勾选下方协议！')
				}

				uni.login({
					provider: 'weixin', //使用微信登录
					success: async (res) => {
						console.log(res, '111111111111111111111');
						let m = await this.$api.login({
							// code: 'test',
							code: res.code,
							parent_id: uni.getStorageSync('code') || 0
						})
						uni.setStorageSync('token', m.data.token)
						let s = await this.$api.loginPhone({
							code: e.detail.code
						})
						if (m.code == 200) {
							this.$msg('登陆成功!')
							// 授权手机号

							let n = await this.$api.userInfo()
							uni.setStorageSync('userInfo', n.data)
							uni.setStorageSync('upload_token', n.data.upload.token)
							uni.setStorageSync('domain', n.data.upload.domain)
							uni.setStorageSync('upload_domain', n.data.upload.endpoint)
							this.$msg(n.msg)
							if (n.code == 200) {
								setTimeout(() => {
									// uni.switchTab({
									// 	url: '/pages/home/index'
									// })
									uni.redirectTo({
										url: '/pageLogin/LaunchPage'
									})
								}, 1000)
							}
						}
						// 存储token
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	* {
		box-sizing: border-box;
	}

	.imgLogo {
		width: 192rpx;
		height: 192rpx;
		margin-left: 50%;
		transform: translateX(-50%);
	}

	.detil {
		height: 800rpx;

		.tit {
			font-weight: 600;
			font-size: 34rpx;
			color: #333333;
		}

		.count {
			height: 600rpx;
			overflow-y: auto;
			font-weight: 400;
			font-size: 30rpx;
			line-height: 1.7;
			color: #333333;
			margin-top: 20rpx;
		}
	}

	.count {
		height: 100vh;
		width: 100%;
		background-color: #fffefc;
	}

	.bottom {
		position: fixed;
		bottom: 150rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;

		.img {
			width: 35rpx;
			height: 35rpx;
			margin-right: 10rpx;
			margin-top: 4rpx;
		}

		.text {
			color: 999999;

			text {
				color: #ccb58d;
			}
		}
	}

	.bg {
		display: flex;
		align-items: center;
		justify-content: center;

		.shou {
			width: 110rpx;
			height: 108rpx;
		}
	}

	.wai {
		padding: 50rpx 40rpx;

		.btn_b {
			margin-top: 30rpx;
			display: flex;
			justify-content: space-between;

			.left_btn {
				width: 248rpx;
				height: 88rpx;
				line-height: 88rpx;
				border: 2rpx solid #eff0f1;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC-Regular;
				font-weight: 400;
				color: #000000;
				border-radius: 86rpx;
				text-align: center;
			}

			.right_btn {
				width: 248rpx;
				height: 88rpx;
				line-height: 88rpx;
				background-color: #276466;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC-Regular;
				font-weight: 400;
				color: #fff;
				border-radius: 86rpx;
				text-align: center;
			}
		}

		.biao_top {
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC-Medium;
			font-weight: 600;
			text-align: CENTER;
			color: #000000;
		}

		.con {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: 400;
			text-align: left;
			color: #000000;
			margin: 30rpx 0;
		}

		.one,
		.tow {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: 400;
			text-align: LEFT;
			color: #333333;
			line-height: 2;
			margin-top: 40rpx;
		}
	}

	.qing {
		margin-top: 50rpx;
		font-size: 36rpx;
		font-family: PingFang SC, PingFang SC-500;
		font-weight: 500;
		text-align: CENTER;
		color: #000000;
	}

	.tit {
		font-size: 48rpx;
		font-family: PingFang SC, PingFang SC-600;
		font-weight: 600;
		text-align: CENTER;
		color: #2f2319;
	}

	.btn {
		border: none;
		width: 90%;
		height: 96rpx;
		border-radius: 48rpx;
		background: #977961;
		font-size: 36rpx;
		font-family: PingFang SC, PingFang SC-500;
		font-weight: 500;
		text-align: CENTER;
		color: #ffffff;
		margin: 0 auto;
		line-height: 96rpx;
		margin-top: 250rpx;
		display: flex;
		align-items: center;
		justify-content: center;

	}

	.btns {
		border: none;
		width: 90%;
		height: 96rpx;
		border-radius: 48rpx;
		background: #f7f6f2;
		font-size: 36rpx;
		font-family: PingFang SC, PingFang SC-500;
		font-weight: 500;
		text-align: CENTER;
		color: #6a5f55;
		margin: 0 auto;
		line-height: 96rpx;
		margin-top: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;

	}
</style>